<template>
  <div class="page">
    <!-- <div class="loader"></div>
    <div style="margin-top: 20px;">跳转中</div> -->

    <van-loading size="54px" type="spinner" color="var(--van-primary-color)" vertical>加载中...</van-loading>
  </div>
</template>

<script lang="ts" setup>
import { useRouter } from "vue-router";
import { reactive, onMounted } from "vue";
import { userStore } from "../stores/userStore";
import Cookies from "js-cookie";
import mockApi from "../api/api.js";
import { getQueryString } from "../utils/utils.js";
const router = useRouter();

let code = getQueryString("code");
let userStoreO = userStore();
console.log("code", code, !code);

// || '09090'
// router.replace({ path: 'in' });
console.log(
  window.location.origin + import.meta.env.VITE_REDIRECT_URI,
  import.meta.env.VITE_APPID,
  import.meta.env.VITE_AGENTID,
  import.meta.env.VITE_SCOPE,
  import.meta.env.VITE_APP_ENV
);

if (import.meta.env.VITE_APP_ENV != "development") {
  if (!code) {
    const REDIRECT_URI =
      window.location.origin + import.meta.env.VITE_REDIRECT_URI;
    const APPID = import.meta.env.VITE_APPID;
    const AGENTID = import.meta.env.VITE_AGENTID;
    const SCOPE = import.meta.env.VITE_SCOPE;
    const state = "state";
    const WX_URL = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APPID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=${SCOPE}&agentid=${AGENTID}&state=${state}#wechat_redirect`;
    console.log("WX_URL", WX_URL);

    window.location.href = WX_URL;
  } else {
    // console.log("codecode", code);
    if (true) {
      mockApi.h5LoginToken({ code }).then((res) => {
        if (res.code == 200) {
          sessionStorage.setItem("jxrs_pc_token", res.data.data);
          router.replace({ path: "/h5/home" });
        }
      });
    }
  }
}
</script>


<style scoped>
.page {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
  color: #3498db;
  font-weight: 600;
}

.loader {
  border: 10px solid #f3f3f3;
  /* Light grey */
  border-top: 10px solid #3498db;
  /* Blue */
  border-radius: 50%;
  width: 70px;
  height: 70px;
  animation: spin 1.5s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}
</style>